package me.jiatao.baselibrary.data.monitor;

import android.app.Application;
import android.util.Log;

import org.greenrobot.eventbus.EventBus;

import me.jiatao.baselibrary.event.NetworkChangeEvent;

public class NetworkMonitor {
    private static NetworkMonitor instance = new NetworkMonitor();

    private NetworkMonitor() {
    }

    public static NetworkMonitor getInstance() {
        return instance;
    }

    public void register(Application application) {
        NetworkManager.getInstance().init(application);
        NetworkManager.getInstance().registerObserver(this);
    }

    public void unRegister() {
        NetworkManager.getInstance().unRegisterObserver(this);
    }

    @NetworkAnnotation(netType = NetType.AUTO)
    public void onNetChanged(NetType netType) {
        Log.e("NetworkMonitor:", netType.name());
        switch (netType) {
            case WIFI:
            case MOBILE:
                EventBus.getDefault().post(new NetworkChangeEvent(true));
                break;
            case NONE:
                EventBus.getDefault().post(new NetworkChangeEvent(false));
                break;
            default:
                break;
        }
    }

//    @NetworkAnnotation(netType = NetType.WIFI)
//    public void onWifiChanged(NetType netType){
//        switch (netType){
//            case WIFI:
//                Log.e(TAG,"wifi监控：WIFI CONNECT");
//                break;
//            case NONE:
//                Log.e(TAG,"wifi监控：NONE CONNECT");
//                break;
//        }
//    }

//    @NetworkAnnotation(netType = NetType.MOBILE)
//    public void onMobileChanged(NetType netType){
//        switch (netType){
//            case MOBILE:
//                Log.e(TAG,"Mobile监控：MOBILE CONNECT");
//                break;
//            case NONE:
//                Log.e(TAG,"Mobile监控：NONE CONNECT");
//                break;
//        }
//    }
}
